package com.netposa.datawarehouse.aggregator.client.search;

import com.alibaba.fastjson.JSON;
import com.netposa.appwebres.common.WebResInfo;
import com.netposa.datawarehouse.aggregator.client.WifiServiceClient;
import com.netposa.datawarehouse.aggregator.web.model.DefaultCondition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

public class WifiResourceSearch extends AbstractResourceSearch {
   private static final Logger log = LoggerFactory.getLogger(WifiResourceSearch.class);
   @Autowired
   private WifiServiceClient wifiServiceClient;

   public Integer count(DefaultCondition ftrCondition) {
      WifiServiceClient.WifiCondition condition = new WifiServiceClient.WifiCondition();
      condition.setFirstCaptureTime(ftrCondition.getStartTime());
      condition.setLastCaptureTime(ftrCondition.getEndTime());
      condition.setDeviceId(ftrCondition.getDeviceIds());
      WebResInfo webResInfo = this.wifiServiceClient.countWifi(JSON.toJSONString(condition));
      if (webResInfo.getCode().equalsIgnoreCase("200") && webResInfo.getData() != null) {
         Double count = Double.valueOf(String.valueOf(webResInfo.getData()));
         return count.intValue();
      } else {
         log.error("Request wifi server failed {} = {} .", webResInfo.getCode(), webResInfo.getMessage());
         return 0;
      }
   }
}
